#ifndef TCPSERVER_H_
#define TCPSERVER_H_

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/socket.h>

#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

#include <sys/syscall.h>  
    
#include <pthread.h>

class TcpServer;

typedef struct 
{
	TcpServer *pTcpServer;
	int sock;
	struct sockaddr_in clienaddr;
}Clientinfo;

class TcpServer
{
public:
	TcpServer(short port, int maxlisten);
	virtual ~TcpServer();
	void start();
	virtual void onAccept(Clientinfo *info);

private:
	static void* acceptLoop(void *pObj);
	static void* callonAccept(void* pinfo);

public:
	short m_port;
	int m_maxlisten;
	int m_serversock;
	static int m_currentconnect;
};

#endif //TCPSERVER_H_